package com.tron.dobest.errorhandler;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.Date;

@Api(tags = "异常处理测试")
@RestController
@Validated
public class TronExceptionTestController {

    @ApiOperation(value = "GET请求参数校验")
    @GetMapping("/exceptionTest01")
    public Object test01(@RequestParam String a) {
        return a;
    }


    @ApiOperation(value = "断言异常")
    @GetMapping("/exceptionTest02")
    public Object test02(@RequestParam String a) {
        Assert.isTrue(a.startsWith("tron"),"断言异常");
        return a;
    }


    @ApiOperation(value = "时间转换异常")
    @GetMapping("/exceptionTest03")
    public Object test03(@RequestParam Date a) {
        return a;
    }


    @ApiOperation(value = "数组长度异常")
    @GetMapping("/exceptionTest04")
    public Object test04(@RequestParam String[] a) {
        return a;
    }


    @ApiOperation(value = "数组元素为空异常")
    @GetMapping("/exceptionTest05")
    public Object test05(@RequestParam @NotEmpty(message = "长度不够！！") String[] a) {
        return a;
    }
}
